function [pts eer] = drawROCCurve(matches,imposters,stepSize,plotTitle)

assert(stepSize <= 1 && stepSize > 0); 

%normalize distances
N=max(max(matches),max(imposters));
matches=matches/N;
imposters=imposters/N;

tao=0:stepSize:1;

n=size(tao,2);

pts=zeros(2,n);

for i=1:n
    
    tp = sum(matches<tao(i));
    fn = size(matches,1)-tp;
   
    fp = sum(imposters<tao(i));
    tn = size(imposters,1)-fp;
    
    %point in ROC space
    pts(:,i) = [fp/(fp+tn);
                tp/(tp+fn)];        
end

%sort by fpr
[~, inds] = sort(pts(1,:),2);

pts = pts(:,inds);

%false positive by false reject
fPts = [pts(1,:);ones(1,n)-pts(2,:)];

%find line segment that crosses eer line
[~,ind] = max(fPts(2,:)<pts(1,:));

if(i > 1)
    %compute intersection with eer line ... 252B was useful :)
    eer=cross([-1 1 0]',cross([fPts(:,ind-1);1],[fPts(:,ind);1]));
    eer=eer(1)/eer(3);
else
    eer = 0;
end

%plot it
figure;
title(plotTitle);
hold on;
plot(pts(1,:),pts(2,:));
hold on;
plot(tao,tao,'--');
hold on;
set(gca,'XLim',[0 1]);
set(gca,'YLim',[0 1]);
lgnd=legend('ROC','Random');
set(lgnd,'Location','East');
hold off;

end

